#!/bin/bash
#description auto install nginx server
user=nginx
group=nginx
SoftDir=/software
InstallDir=/application
LogDir=/log
function init_install {
  cd /etc/yum.repos.d
  for name in epel Centos;do
                if [ ! -f ${name}-6.repo ];then
                        wget -O /etc/yum.repos.d/${name}-6.repo http://mirrors.aliyun.com/repo/${name}-6.repo
                fi
   done
   [ -d $SoftDir ] || mkdir $SoftDir
   [ -d $InstallDir ] || mkdir $InstallDir 
   [ -d $LogDir ] || mkdir $LogDir
   /usr/bin/yum  -y install gcc gcc-c++ vim wget ntpdate openssl openssl-devel geoip-devel gd-devel pcre-devel pcre 
}
if [ $# -ne 1 ];then
	echo "Usage:$0 <Nginx-Version>"
	exit 0
fi
Nginx_version=$1
function install_nginx {
	init_install
	if ! id $user &>/dev/null;then 
             groupadd -g 7001 nginx
	     useradd -u 7001 -g nginx -s /sbin/nologin nginx
	fi
	cd $SoftDir && wget http://nginx.org/download/${Nginx_version}.tar.gz
	tar xf ${Nginx_version}.tar.gz && cd ${Nginx_version} &&  ./configure --prefix=/usr/local/${Nginx_version} --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-poll_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_geoip_module --with-http_flv_module --with-http_ssl_module --with-http_mp4_module --with-http_gzip_static_module --with-http_dav_module --with-http_stub_status_module --with-pcre && make && make install
	ln -sv /usr/local/${Nginx_version} /usr/local/nginx
}
install_nginx 
